package com.zhaopin.netty.tianyuan;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageCodec;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
import io.netty.handler.codec.json.JsonObjectDecoder;

import java.util.List;

/**
 * Created by thamy on 2019/9/24.
 */
@ChannelHandler.Sharable
public class PokerCodec extends MessageToMessageCodec<WebSocketFrame, String> {

    @Override
    protected void encode(ChannelHandlerContext ctx, String msg, List<Object> out) {
        WebSocketFrame frame = new TextWebSocketFrame(msg);
        out.add(frame);
    }

    @Override
    protected void decode(ChannelHandlerContext ctx, WebSocketFrame msg, List<Object> out) {
        TextWebSocketFrame frame = (TextWebSocketFrame)msg;
        String content = frame.text();
        out.add(content);
    }
}
